﻿Public Class frmCourseAdd
    Private Sub cmdAdd_Click(sender As Object, e As EventArgs) Handles cmdAdd.Click
        If Trim(txtCourse_NO.Text) = "" Then
            MsgBox("请输入课程编号", vbOKOnly, "警告")
            txtCourse_NO.Focus()
            Exit Sub
        End If
        If Trim(txtCourse_name.Text) = "" Then
            MsgBox("请输入课程名称", vbOKOnly, "警告")
            txtCourse_name.Focus()
            Exit Sub
        End If
        If Trim(txtCourse_type.Text) = "" Then
            MsgBox("请输入课程类别", vbOKOnly, "警告")
            txtCourse_type.Focus()
            Exit Sub
        End If
        If Trim(txtCourse_credit.Text) = "" Then
            MsgBox("请输入学分", vbOKOnly, "警告")
            txtCourse_credit.Focus()
            Exit Sub
        End If
        If Not IsNumeric(txtCourse_credit.Text) Then
            MsgBox("请输入正确的学分", vbOKOnly, "警告")
            txtCourse_credit.Focus()
            Exit Sub
        End If
        If Trim(txtCourse_des.Text) = "" Then
            MsgBox("请输入课程描述", vbOKOnly, "警告")
            txtCourse_des.Focus()
            Exit Sub
        End If

        Dim icount As Integer
        txtSQL = "SELECT * FROM 课程 WHERE 课程编号 ='" & Trim(txtCourse_NO.Text) & "'"
        icount = ExecuteSQL(txtSQL, ErrorMsg)
        If icount > 0 Then
            MsgBox("课程编号重复，请重新输入！"， vbOKOnly, "警告")
            txtCourse_NO.Focus()
        Else
            txtSQL = "INSERT INTO 课程(课程编号,课程名称,课程类别,学分,课程描述)"
            txtSQL = txtSQL & "VALUES('" & txtCourse_NO.Text & "','" & txtCourse_name.Text & "','" & txtCourse_type.Text & "','" & txtCourse_credit.Text & "','" & txtCourse_des.Text & "')"
            icount = ExecuteSQL(txtSQL, ErrorMsg)
            If icount > 0 Then
                MsgBox("新增成功")
            Else
                MsgBox("新增成功")
            End If
        End If
    End Sub

    Private Sub cmdExit_Click(sender As Object, e As EventArgs) Handles cmdExit.Click
        Me.Close()
    End Sub
End Class